﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Uc_menu_fv.ascx.vb" Inherits="Apps_Shares_Uc_menu_fv" %>
<asp:FormView ID="fv" runat="server" RenderOuterTable="False" DefaultMode="Edit"
    DataSourceID="fvSrc" EnableModelValidation="True" Width="100%">
    <InsertItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="75%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อเมนูระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtSystemName' runat='server' CssClass='text_normal' Text='<%# Bind("menu_system_name") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlSystem' runat='server' AppendDataBoundItems="True" DataTextField="main_system_name"
                            DataValueField="main_system_code" SelectedValue='<%# Bind("main_system_code") %>'
                            DataSourceID='ddlSystemSrc'>
                            <asp:ListItem Text='ระบบ' Value='0'></asp:ListItem>
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="ddlSystemSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                            SelectCommand="
                            select main_system_name , main_system_code 
                            from stp_main_system
                            where main_system_type>0 and main_system_status = 1">
                        </asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">URL :</td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtURL' runat='server' Text='<%# Bind("menu_system_url") %>'></asp:TextBox>(http://127.0.0.1)
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:RadioButtonList ID='rblStatus' runat='server' RepeatDirection="Horizontal" RepeatLayout="Flow"
                            SelectedValue='<%# Bind("menu_system_status") %>'>
                            <asp:ListItem Text='ใช้งาน' Value='1' Selected='True'></asp:ListItem>
                            <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='บันทึก' CommandName="Insert" ValidationGroup='g1' />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                        <div class="hide">
                            <asp:RequiredFieldValidator ID="txtSystemNameRequiredFieldValidator" runat="server"
                                ControlToValidate="txtSystemName" ErrorMessage="กรุณากรอกชือเมนูระบบ" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlSystemRequiredFieldValidator" runat="server" ControlToValidate="ddlSystem"
                                ErrorMessage="กรุณาเลือกระบบงาน" InitialValue="0" SetFocusOnError="True" ValidationGroup="g1">
                            </asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="rblStatusRequiredFieldValidator" runat="server" ControlToValidate="rblStatus"
                                ErrorMessage="<%$ Resources:Resource, MSG_REQ_STATUS %>" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <%--<asp:RegularExpressionValidator ID="txtURLRegularExpressionValidator" 
                            runat="server" ControlToValidate="txtURL" 
                            ErrorMessage="กรุณาระบุรูปแบบ URL ให้ถูกต้อง" SetFocusOnError="True" 
                            ValidationExpression="^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&amp;amp;%\$#_]*)?$" 
                            ValidationGroup="g1"></asp:RegularExpressionValidator>--%>
                            <br />
                            <asp:ValidationSummary ID="fvValidationSummary" runat="server" ShowMessageBox="True"
                                ValidationGroup="g1" />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </InsertItemTemplate>
    <EditItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อเมนูระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtSystemName' runat='server' CssClass='text_normal' Text='<%# Bind("menu_system_name") %>'></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อระบบ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:DropDownList ID='ddlSystem' runat='server' AppendDataBoundItems="True" DataTextField="main_system_name"
                            DataValueField="main_system_code" SelectedValue='<%# Bind("main_system_code") %>'
                            DataSourceID='ddlSystemSrc'>
                            <asp:ListItem Text='ระบบ' Value='0'></asp:ListItem>
                        </asp:DropDownList>
                        <asp:SqlDataSource ID="ddlSystemSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
                            SelectCommand="
                            select main_system_name , main_system_code 
                            from stp_main_system
                            where main_system_type > 0 and main_system_status = 1">
                        </asp:SqlDataSource>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">URL :</td>
                    <td align="left" class="td_box">
                        <asp:TextBox ID='txtURL' runat='server' Text='<%# Bind("menu_system_url") %>'></asp:TextBox>(http://127.0.0.1)
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ <span class="star">*</span> :
                    </td>
                    <td align="left" class="td_box">
                        <asp:RadioButtonList ID='rblStatus' runat='server' RepeatDirection="Horizontal" RepeatLayout="Flow"
                            SelectedValue='<%# Bind("menu_system_status") %>'>
                            <asp:ListItem Text='ใช้งาน' Value='1' Selected='True'></asp:ListItem>
                            <asp:ListItem Text='ไม่ใช้งาน' Value='2'></asp:ListItem>
                        </asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่สร้างข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        <asp:Literal ID='ltrCreate' runat='server' Text='<%# Eval("Creator") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่ปรับปรุงข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        <asp:Literal ID='ltrUpdate' runat='server' Text='<%# Eval("Editor") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnSubmit' runat='server' Text='บันทึก' CommandName="Update" ValidationGroup="g1" />
                        <asp:Button ID='btnCancel' runat='server' Text='ยกเลิก' PostBackUrl="~/Apps/menu_list.aspx?Edit=true" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                        <div class="hide">
                            <asp:RequiredFieldValidator ID="txtSystemNameRequiredFieldValidator" runat="server"
                                ControlToValidate="txtSystemName" ErrorMessage="กรุณากรอกชือเมนูระบบ" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="ddlSystemRequiredFieldValidator" runat="server" ControlToValidate="ddlSystem"
                                ErrorMessage="กรุณาเลือกระบบงาน" SetFocusOnError="True" ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <asp:RequiredFieldValidator ID="rblStatusRequiredFieldValidator" runat="server" ControlToValidate="rblStatus"
                                ErrorMessage="<%$ Resources:Resource, MSG_REQ_STATUS %>" SetFocusOnError="True"
                                ValidationGroup="g1"></asp:RequiredFieldValidator>
                            <br />
                            <br />
                            <asp:ValidationSummary ID="fvValidationSummary" runat="server" ShowMessageBox="True"
                                ValidationGroup="g1" />
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </EditItemTemplate>
    <ItemTemplate>
        <table cellspacing="2" cellpadding="2" bordercolor="#cccccc" border="1" align="center"
            width="60%">
            <tbody>
                <tr>
                    <td bgcolor="#999999" align="center" class="th_data" colspan="2">
                        &nbsp;
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อเมนูระบบ :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='txtSystemName' runat='server' Text='<%# Eval("menu_system_name") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อระบบ :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ddlSystem' runat='server' Text='<%# CodeMatrix.Business.GenericData.GetMainSystemNameLabel(me,Eval("main_system_code")) %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        URL :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='txtURL' runat='server' Text='<%# Eval("menu_system_url") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        สถานะ :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='rblStatus' runat='server' Text='<%# CodeMatrix.Business.GenericData.GetStatusLabel(Eval("menu_system_status")) %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่สร้างข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrCreate' runat='server' Text='<%# Eval("Creator") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td align="right" class="td_box">
                        ชื่อและวันเวลาที่ปรับปรุงข้อมูล :
                    </td>
                    <td align="left" class="td_box">
                        &nbsp;
                        <asp:Literal ID='ltrUpdate' runat='server' Text='<%# Eval("Editor") %>'></asp:Literal>
                    </td>
                </tr>
                <tr>
                    <td bgcolor="#999999" align="center" class="td_data_end" colspan="2">
                        <asp:Button ID='btnBack' runat='server' Text='ย้อนกลับ' PostBackUrl="~/Apps/menu_list.aspx" />
                        <asp:Button ID='btnMainMenu' Text='<%$ Resources:Resource,BTN_MAINMENU %>' runat='server' PostBackUrl="~/Apps/ViewSystem.aspx?Edit=2" />
                    </td>
                </tr>
            </tbody>
        </table>
    </ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="fvSrc" runat="server" ConnectionString="<%$ ConnectionStrings:ApplicationServices %>"
    InsertCommand="INSERT INTO [stp_menu_system]
           ([main_system_code]
           ,[menu_system_name]
           ,[menu_system_url]
           ,[menu_system_status]
           ,[staff_code_create]
           ,[create_datetime]
           ,[staff_code_update]
           ,[update_datetime])
     VALUES
           (@main_system_code
           ,@menu_system_name
           ,@menu_system_url
           ,@menu_system_status
           ,@staff_code_create
           ,getdate()
           ,@staff_code_update
           ,getdate())" SelectCommand="select * ,
Creator = dbo.UFN_GetAuditor(staff_code_create,create_datetime) ,
Editor = dbo.UFN_GetAuditor(staff_code_update,update_datetime) 
from stp_menu_system
where menu_system_code = @menu_system_code" UpdateCommand="UPDATE [stp_menu_system]
SET	   [menu_system_name] = @menu_system_name
      ,[menu_system_url] = @menu_system_url
      ,[menu_system_status] = @menu_system_status
      ,[staff_code_update] = @staff_code_update
      ,[update_datetime] = getdate()
		,[main_system_code] = @main_system_code
WHERE menu_system_code = @menu_system_code
">
    <InsertParameters>
        <asp:Parameter Name="menu_system_name" />
        <asp:Parameter Name="menu_system_url" />
        <asp:Parameter Name="menu_system_status" />
        <asp:SessionParameter Name="staff_code_create" SessionField="staff_code" />
        <asp:SessionParameter Name="staff_code_update" SessionField="staff_code" />
        <asp:Parameter Name="main_system_code" />
    </InsertParameters>
    <SelectParameters>
        <asp:QueryStringParameter Name="menu_system_code" QueryStringField="Edit" />
    </SelectParameters>
    <UpdateParameters>
        <asp:Parameter Name="menu_system_name" />
        <asp:Parameter Name="menu_system_url" />
        <asp:Parameter Name="menu_system_status" />
        <asp:SessionParameter Name="staff_code_update" SessionField="staff_code" />
        <asp:Parameter Name="main_system_code" />
        <asp:QueryStringParameter Name="menu_system_code" QueryStringField="Edit" />
    </UpdateParameters>
</asp:SqlDataSource>
